//
//  XSJMyOrderTableCell.m
//  ZF
//
//  Created by apple on 2019/3/18.
//  Copyright © 2019 hyy. All rights reserved.
//

#import "XSJMyOrderTableCell.h"
#import "XSJMyOrderCollectionCell.h"
#import "UIView+HJViewStyle.h"


@interface XSJMyOrderTableCell ()<UICollectionViewDelegate, UICollectionViewDataSource,XSJMyOrderCollectionCellDelegate>

@property (nonatomic, strong) UICollectionView* collectionView;

@end


@implementation XSJMyOrderTableCell

static NSString *const XSJMyOrderCollectionCellID = @"XSJMyOrderCollectionCellID";


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setup];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setup
{
    self.contentView.backgroundColor = TableViewBGColor;
    [self.contentView addSubview:self.collectionView];
    
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(70);
    }];
}


#pragma mark - dataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    XSJMyOrderCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:XSJMyOrderCollectionCellID forIndexPath:indexPath];
    if (indexPath.item==0)
    {
        cell.title = @"消息";
        cell.iconName = @"message";
    }
    else if (indexPath.item==1)
    {
        cell.title = @"任务";
        cell.iconName = @"assignment";
    }
    else if (indexPath.item==2)
    {
        cell.title = @"财产";
        cell.iconName = @"property";
    }
    else if (indexPath.item==3)
    {
        cell.title = @"已购买";
        cell.iconName = @"PAY";
    }
    
    cell.indexPath = indexPath;
    cell.delegate = self;
    
    return cell;
}


//预览cell点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
   
}


/**
 消息被点击
 */
- (void)XSJMyOrderCollectionCellDidClick:(NSIndexPath*)indexPath
{
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(XSJMyOrderTableCellDidClick:)])
    {
        [self.delegate XSJMyOrderTableCellDidClick:indexPath];
    }
}

- (UICollectionView *)collectionView {
    if (_collectionView == nil)
    {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        float fw = (kScreenWidth-30)/4;
        layout.itemSize = CGSizeMake(fw, 70);
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        
        //圆角
        _collectionView.cornerRadius = 5.0f;
        _collectionView.shadowColor =  ColorHex(0xF4F4F4);
//        _collectionView.shadowRadius = 1.0f;
        
//        _collectionView.layer.cornerRadius = 5.0f;
//        _collectionView.clipsToBounds = YES;
        
         [_collectionView registerClass:[XSJMyOrderCollectionCell class] forCellWithReuseIdentifier:XSJMyOrderCollectionCellID];
    }
    return _collectionView;
}

@end
